home *** CD-ROM | disk | FTP | other *** search
/ Computer Select (Limited Edition) / Computer Select.iso / pcmag / v11n08 / wprints.exe / WPRINC.EXE / WNDPROC.C < prev    next >
C/C++ Source or Header  |  1992-04-10  |  5KB  |  140 lines

  1. #include <windows.h>
  2. #include <shellapi.h> 
  3. #include <direct.h>
  4. #include <errno.h>
  5. #include "wprint.h"
  6.  
  7. /////////////////////////////////////////////////////////////////////////
  8. //
  9. //  MainWndProc - window procedure for parent window
  10. //
  11. //  hWnd: Handle of parent window.
  12. //  message: message number WM_?
  13. //  wParam: word containing extra information about message param.
  14. //  lParam: dword containing extra information about message param.
  15. //
  16. /////////////////////////////////////////////////////////////////////////
  17.  
  18. long FAREXPORT MainWndProc(hWnd, message, wParam, lParam)
  19. HWND hWnd;
  20. unsigned message;
  21. WORD wParam;
  22. LONG lParam;
  23. {
  24.     switch (message) {
  25.       case WM_CREATE:
  26.       {
  27.         int nScaling = GetProfileInt ((LPSTR)"WinPrint\0",
  28.                                     (LPSTR)"Scale\0",
  29.                                     (int)-1) - 1;
  30.         int nMagnifyBy = GetProfileInt ((LPSTR)"WinPrint\0",
  31.                                     (LPSTR)"MagnifyBy\0",
  32.                                     (int)-1) ;
  33.         if (nScaling < 0 || nMagnifyBy < 0)
  34.                 PostMessage (hWnd, WM_SYSCOMMAND, IDM_SETTINGS, 0L);
  35.       }
  36.       break ;
  37.       
  38.       case WM_DROPFILES:
  39.  
  40.          if ((wNumDrop = DragQueryFile (wParam,-1,NULL,0)) > 0){
  41.  
  42.             if (NULL==(hDragList = GlobalAlloc (GHND, sizeof (DRAGLIST) * wNumDrop))){
  43.                 Error (IDS_NOALLOC);
  44.                 goto DragErr0;
  45.             }
  46.  
  47.             if (NULL==(lpDragList = (LPDRAGLIST) GlobalLock (hDragList))){
  48.                 Error (IDS_NOLOCK);
  49.                 goto DragErr1;
  50.             }
  51.  
  52.             for (i = 0; i < (int) wNumDrop; i++) 
  53.                 DragQueryFile (wParam,i,lpDragList[i].szFileName,FILE_NAME_SIZE);
  54.  
  55.             PrintDragList ();
  56.  
  57.             GlobalUnlock (hDragList) ;
  58. DragErr1:
  59.             GlobalFree (hDragList) ;
  60.          }
  61. DragErr0:
  62.  
  63.          break;
  64.  
  65.       case WM_QUERYOPEN:
  66.          /* When the user double-clicks on the icon, I get a 
  67.             WM_QUERYOPEN message.  All I do from here is
  68.             display a dialog box which shows printer settings */
  69.          PostMessage (hWnd, WM_SYSCOMMAND, IDM_SETTINGS, 0L);
  70.          return 0L;
  71.  
  72.         case WM_SYSCOMMAND:
  73.             switch (wParam){
  74.                 FARPROC lp;
  75.                 case IDM_ABOUT:
  76.                     lp = MakeProcInstance(About, hInst);
  77.                     DialogBox (hInst,"ABOUTBOX",hWnd,lp);
  78.                     FreeProcInstance (lp);
  79.                     break ;
  80.                 case IDM_SETTINGS:
  81.                     lp = MakeProcInstance (INIDlgProc, hInst);
  82.                     DialogBox (hInst, "Settings", hWndParent, lp);
  83.                     FreeProcInstance (lp);
  84.                     break ;
  85.                 case IDM_PRINT:
  86.                     eszFile[0] = '\0';       
  87.                     _getcwd (eszDirName,sizeof(eszDirName));                    
  88.                     
  89.                     eofn.lStructSize = sizeof (OPENFILENAME);
  90.                     eofn.hwndOwner = hWnd;
  91.                     eofn.lpstrFilter = eszFilter[0];
  92.                     eofn.lpstrCustomFilter = (LPSTR) NULL;
  93.                     eofn.nMaxCustFilter = 0L;
  94.                     eofn.nFilterIndex = 1L;
  95.                     eofn.lpstrFile = eszFile;
  96.                     eofn.nMaxFile = sizeof (eszFile);
  97.                     eofn.lpstrFileTitle = eszFileTitle;
  98.                     eofn.nMaxFileTitle = sizeof (eszFileTitle);
  99.                     eofn.lpstrInitialDir = eszDirName;
  100.                     eofn.lpstrTitle = (LPSTR)"WinPrint Print File...\0";
  101.                     eofn.Flags = 0;
  102.                     eofn.nFileOffset = 0;
  103.                     eofn.nFileExtension = 0;
  104.                     eofn.lpstrDefExt = (LPSTR)NULL;
  105.  
  106.                     if (GetOpenFileName(&eofn)){
  107.                         if (NULL==(hDragList = 
  108.                                    GlobalAlloc (GHND, sizeof (DRAGLIST)))){
  109.                             Error (IDS_NOALLOC);
  110.                             break;
  111.                         }
  112.  
  113.                         if (NULL==(lpDragList = 
  114.                                    (LPDRAGLIST) GlobalLock (hDragList))){
  115.                             Error (IDS_NOLOCK);
  116.                             GlobalUnlock (hDragList);GlobalFree(hDragList);
  117.                             break;
  118.                         }
  119.                         lstrcpy (lpDragList[0].szFileName,eszFile);
  120.                         wNumDrop = 1;
  121.                         PrintDragList();
  122.                         GlobalUnlock (hDragList);GlobalFree(hDragList);
  123.                     }
  124.                     return 0L;
  125.  
  126.                     break ;
  127.                 default:
  128.                     break ;
  129.             }
  130.             break ;
  131.  
  132.         case WM_DESTROY:
  133.             PostQuitMessage(0);
  134.             break;
  135.     }
  136.     return (DefWindowProc(hWnd, message, wParam, lParam));
  137. }
  138.  
  139.  
  140.